package main

import (
	"fmt"
	"github.com/gin-gonic/gin/binding"
	"github.com/go-playground/validator/v10"
	"go.uber.org/zap"
	"web_end/global"
	"web_end/initialize"
	v "web_end/validator"
)

func main() {
	// 初始化viper
	initialize.InitConfig()
	// 初始化logger
	initialize.InitLogger()
	// 初始化redis
	initialize.InitRedis()
	// 初始化路由
	router := initialize.Routers()

	// 注册验证器
	validate := binding.Validator.Engine().(*validator.Validate)
	err := validate.RegisterValidation("mobile", v.ValidatorMobile)
	if err != nil {
		panic(err)
	}

	port := global.ServerConfig.Port

	zap.S().Infof("启动服务器，端口：%d", port)
	if err := router.Run(fmt.Sprintf(":%d", port)); err != nil {
		zap.S().Panic("启动失败", err.Error())
	}
}
